package org.jeecgframework.boot.springaimcpservice;

import org.jeecgframework.boot.springaimcpservice.service.ExpertPersonToolService;
import org.jeecgframework.boot.springaimcpservice.service.OpenMeteoService;
import org.jeecgframework.boot.springaimcpservice.service.StatsQueryToolService;
import org.springframework.ai.tool.ToolCallback;
import org.springframework.ai.tool.ToolCallbackProvider;
import org.springframework.ai.tool.function.FunctionToolCallback;
import org.springframework.ai.tool.method.MethodToolCallbackProvider;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Bean;
import org.springframework.web.client.RestTemplate;

@SpringBootApplication

public class SpringAiMcpServiceApplication {

    public static void main(String[] args) {
        SpringApplication.run(SpringAiMcpServiceApplication.class, args);
    }
    
    @Bean
    public RestTemplate restTemplate() {
        return new RestTemplate();
    }
    
    @Bean
    public ToolCallbackProvider weatherTools(OpenMeteoService openMeteoService) {
        return MethodToolCallbackProvider.builder().toolObjects(openMeteoService).build();
    }

    @Bean
    public ToolCallbackProvider expertTools(ExpertPersonToolService expertPersonToolService) {
        return MethodToolCallbackProvider.builder().toolObjects(expertPersonToolService).build();
    }
    
    @Bean
    public ToolCallbackProvider statsQueryTools(StatsQueryToolService statsQueryToolService) {
        return MethodToolCallbackProvider.builder().toolObjects(statsQueryToolService).build();
    }


    public record TextInput(String input) {
    }

    /**
     * 将输入字母转为大写的 MCP Tools
     */
    @Bean
    public ToolCallback toUpperCase() {
        return FunctionToolCallback.builder("toUpperCase", (TextInput input) -> input.input().toUpperCase())
                .inputType(TextInput.class)
                .description("Put the text to upper case")
                .build();
    }

}